<template>
	<view >
		<view class="overflow-hidden  pt-4 px-8">
			<view class="flex overflow-x-scroll" :class='props.fixed?"flex-x-space-around":""'
				style="scrollbar-height: none;">
				<view v-for="(item,index) in props.list" :key='index'>
					<view class="px-12 p-8" :class="props.modelValue==item[props.field]?'line fw-bold' : ''"
						@click="changeCate(item,index)">
						<text class="fs-15 text-nowrap text-white">{{item.label}}</text>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script setup>
	import { ref, defineProps, } from 'vue'
	const emit = defineEmits(['change', 'update:modelValue'])
	const props = defineProps({
		modelValue: {
			default: '',
			type: [Number, String]
		},
		list: {
			default: [],
			type: Array
		},
		fixed: {
			default: false,
			type: Boolean
		},
		field: {
			default: 'value',
			type: String
		}
	})
	const changeCate = (e, index) => {
		emit('update:modelValue', e[props.field])
		emit('change', e)
	}
</script>

<style>
	.line {
		background: linear-gradient(90deg, #319cff 100%, #319cff 100%);
		background-size: 40% 6rpx;
		background-repeat: no-repeat;
		background-position: bottom;
	}
</style>